package com.wgworkshop.pems.controller;

import com.wgworkshop.pems.model.UserModel;
import com.wgworkshop.pems.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器。
 * Created by lcwang on 2018/3/23.
 */
@RestController
@RequestMapping("/users")
public class UserController {
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    ResponseEntity<UserModel> login(@RequestBody UserModel userModel) {
        UserModel resultModel = userService.login(userModel);
        return ResponseEntity.ok(resultModel);
    }

    @GetMapping("/{account}")
    ResponseEntity<UserModel> find(@PathVariable("account") String account) {
        UserModel userModel = userService.getUserByAccount(account);
        return ResponseEntity.ok(userModel);
    }
}
